$(function () {
	var popMenufuncid;

	var focusNum = 0; 
    /* 设置右侧历史信息滚动条 */
    $(".historyHeight").height($(window).height() - 50 + "px");
    $(".tab-pane").height($(".control-sidebar-halfheight").height() - 88 + "px");
    var timeoutflag = null;
    $(".smokeHistoryTwinkle").click(function (){
    	if($(".control-sidebar.control-sidebar-open").length=="1"){
    	var alarmTypeCode="";
    	var deviceTypeId="";
    	if(devHeader == "smokeHeader"){
    		$(".alarmhistorybtn i").removeClass("cover-alarm-tab humiture-alarm-tab").addClass("fire-alarm-tab");
    		alarmTypeCode = "001";
    		deviceTypeId = "001";
    		$(".lowhistorybtn").show();
    	}else if(devHeader == "manholeCoverHeader"){
    		$(".alarmhistorybtn i").removeClass("fire-alarm-tab humiture-alarm-tab").addClass("cover-alarm-tab");
    		deviceTypeId = "005";
    		alarmTypeCode = "010";
    		$(".lowhistorybtn").show();
    	}else if(devHeader == "humitureHeader"){
    		$(".alarmhistorybtn i").removeClass("fire-alarm-tab cover-alarm-tab").addClass("humiture-alarm-tab");
    		deviceTypeId = "007";
    		alarmTypeCode = "061";
    		$(".lowhistorybtn").hide();
    		
    	}
            if (timeoutflag != null) {
                clearTimeout(timeoutflag);
                timeoutflag = null;
            } else {
                timeoutflag = setTimeout(function () {
		    	$(".object-ul").html("");
		    	$('#control-sidebar-settings-tab').html("");
		    	$('#control-sidebar-home-tab').html("");
		    	$('#control-sidebar-theme-demo-options-tab').html("");
		    		//烟感历史消息的接口,定义url变量
		    		
		    	    $.ajax({
		    	        url: '/alarm/data/device/focusbycount',
		    	        type: 'GET',
		    	        async : false, //同步执行
		    	        success: function (result) {
		    	            if (result.status == 200) {
		    	            	moreThanNum = result.data;
		    	                return moreThanNum;
		    	            } else {
		    	            	winTip.alert(data.message)
		    	            }
		    	        }
		    	    });
		    	    $.ajax({
		    	        url: "/alarm/data/device/count?beginTime="+beginTime1+"&endTime="+endTime1+"&alarmTypeCode="+alarmTypeCode+"&deviceTypeId="+deviceTypeId,
		    	        type: 'GET',
		    	        async : false, //同步执行
		    	        success: function (result) {
		    	            if (result.status == 200) {
		    	                for (var i = 0; i < result.data.length; i++) {
		    	                    var data = result.data[i];
		    	                    focusNum = data[1];
		    	                    $(".sidebar-content-title >span").html('（'+result.data.length+'）');//— 近七天报警超过 '+moreThanNum+' 条的设备
		    	            	    $(".object-ul").append('<li latitude='+data[0].latitude+' longitude='+data[0].longitude+' devicecode='+data[0].devCode+'><span class="label label-primary">'+focusNum+'</span><span class="object-address">'+data[0].address+'</span></li>');
		    	            	}
		    	            } else {
		    	            	winTip.alert(result.message);
		    	            }
		    	        }
		    	    });
		    	    /* 报警历史信息记录 */
		    	    $.ajax({
		    	        url: "/alarm/data/history/simple/list?beginTime="+beginTime+"&endTime="+endTime+"&deviceTypeId="+devTypeId,
		    	        type: 'GET',
		    	        async : false,
		    	        success: function (result) {
		    	            if (result.status == 200) {
		    	                for (var i = 0; i < result.data.length; i++) {
		    	                    var data = result.data[i];
		    	                	var  devCode= data[0];
		    	                	var deviceName = data[1];
		    	                	var latitude = data[2];
		    	                	var longitude = data[3];
		    	                	var address = data[4];
		    	                	var alarmCode = data[5];
		    	                	var beginTime = moment(data[6]).format("YYYY-MM-DD HH:mm:ss");
		    	                    addHistoryNews(devCode,deviceName,latitude,longitude,address,alarmCode,beginTime);
		    	                    timeoutflag = null;
		    	                }
		    	            } else {
		    	            	winTip.alert(result.message)
		    	            }
		    	        }
		    	    });
		    	    
                },0);
                var timeoutflag = null;
            }
    	}
    });
    
    /* 点击历史消息定位到地图 */
    $(".historyList").on('click', '.li_device', function () {
        var li = $(this);
        if(li.hasClass("notclick"))
        	return;
        var devicecode = li.attr("devicecode");
        var latitude = li.attr("latitude");
        var longitude = li.attr("longitude");
        var statusAbbr = li.attr("statusAbbr");
        map.setZoom(20); 
        $('.BMap_pop').parent().show();
    	$(".BMap_shadow").parent().show();
    	
//        clearTimeout(popMenufuncid);
        BaiDuMap.panTo(latitude, longitude);
        $(".active-alarm-pointer .pulse").remove();
        $(".active-alarm-pointer .pulse1").remove();
//        BaiDuMap.popMenufuncid = setTimeout(function(){
        BaiDuMap.popMenu(devicecode);
//    	},500);
        
    });

    /*重点关注对象*/
//    focusAttention();
  //点击重点关注对象定位地图
    $(".object-ul").on('click', 'li', function (e) {
        var li = $(this);
        var devicecode = li.attr("devicecode");
        var latitude = li.attr("latitude");
        var longitude = li.attr("longitude");
        map.setZoom(20);
        BaiDuMap.panTo(latitude, longitude);
        $(".active-alarm-pointer .pulse").remove();
        $(".active-alarm-pointer .pulse1").remove();
//        地图信息框显示
        $('.BMap_pop').parent().show();
    	$(".BMap_shadow").parent().show();
    	BaiDuMap.popMenu(devicecode);
    });
    
  }); 
